﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Security.Cryptography;
using System.Text;

namespace NetCoreCMS.Common
{
    public class KuaiDi100
    {
        /// <summary>
        /// 快递100查询API
        /// </summary>
        /// <param name="com">哪家快递shunfen,yuantong</param>
        /// <param name="num">单号</param>
        /// <param name="customer">客户号</param>
        /// <param name="key">APIkey</param>
        /// <returns></returns>
        public static string Check(string com,string num,string customer,string key,string url)
        {
            #region 加密
            String param = "{\"com\":\"" + com + "\",\"num\":\"" + num + "\",\"from\":\"\",\"to\":\"\"}";
            MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
            byte[] InBytes = Encoding.GetEncoding("UTF-8").GetBytes(param + key + customer);
            byte[] OutBytes = md5.ComputeHash(InBytes);
            string OutString = "";
            for (int i = 0; i < OutBytes.Length; i++)
            {
                OutString += OutBytes[i].ToString("x2");
            }
            String sign = OutString.ToUpper(); 
            #endregion
            string pars= "customer=" + customer + "&sign=" + sign + "&param=" + param;
            string html = Utils.HttpPost(url, pars);            
            return html;
        }
    }
}
